<template>
  <div class="mt-4 pl-4  box-border w-auto">
    <div class="flex w-auto items-end">
      <el-button type="primary" @click="handleAdd">新增</el-button>
    </div>

    <el-table class="mt-4" :data="tableData" border style="width:85vw">
      <el-table-column prop="id" label="序号" width="150px"></el-table-column>
      <el-table-column prop="grade" label="阶段等级"></el-table-column>
      <el-table-column prop="name" label="等级阶段名称"></el-table-column>
      <el-table-column prop="big_img" label="展示大图(mp4)">
        <template slot-scope="{ row }">
          <el-popover placement="right" max-width="420" trigger="hover">
            <img :src="row.big_img" alt="" style="max-width: 200px; max-height: 200px"/>
            <img slot="reference" :src="row.big_img" alt="" style="width: 50px"/>
          </el-popover>
        </template>
      </el-table-column>
      <el-table-column prop="privilege_data" label="等级特权">
        <template slot-scope="{ row }">
          <div class="flex flex-wrap">
            <div class="privilege mr-2 mt-2 flex justify-center items-center" v-for="item in row.privilege_data">
              {{ item.name }}
            </div>
          </div>
        </template>
      </el-table-column>
      <el-table-column label="操作">
        <template slot-scope="scope">
          <el-button type="primary" plain size="mini" icon="el-icon-edit" @click="deBounceWrap(handleEdit, scope.row)">编辑</el-button>
          <el-button type="info" plain size="mini" @click="deBounceWrap(handleDetail, scope.row)">详情</el-button>
          <el-popconfirm
            class="ml-2"
            title="确认删除吗？"
            @confirm="deBounceWrap(handleDel, scope.row)"
          >
            <el-button slot="reference" type="danger" plain size="mini">删除</el-button>
          </el-popconfirm>
        </template>
      </el-table-column>
    </el-table>

    <TMPagination
      style="width: 85vw"
      :current-page.sync="pageList.page"
      :total.sync="pageList.total"
      :page-size.sync="pageList.page_size"
      @updateTable="getTable"
    />

    <indexAddEdit :dialog-visible.sync="model.visible" @updateTable="getTable" :detail="model.detail" :status.sync="model.status"/>
  </div>
</template>

<script>
import { getTableData, privilegeDelete } from "@/api/dailyCheck/vipLevelManagement";
import indexAddEdit from "@/views/dailyCheck/vipLevelManagement/childComps/indexAddEdit";

import TMPagination from "@/views/personalizedMall/wishList/childComps/TMPagination/TMPagination";

export default {
  name: "index",
  components: { TMPagination, indexAddEdit },
  data() {
    return {
      tableData: [],
      pageList: {
        page: 1,
        total: 10,
        page_size: 10
      },
      model: {
        visible: false,
        status: 'Add',
        detail: {}
      }
    }
  },
  created() {
    this.getTable()
  },
  methods: {
    async getTable() {
      const { data } = await getTableData(this.pageList.page, this.pageList.page_size)
      this.tableData = data.data
      this.pageList.total = data.total
    },
    handleAdd() {
      this.model.status = 'Add'
      this.model.visible = true
    },
    handleEdit(row) {
      this.model.detail = row
      this.model.status = 'Edit'
      this.model.visible = true
    },
    handleDetail(row) {
      this.$router.push({
        name: 'vipLevelManagementDetail',
        query: {
          name: row.name,
          id: row.id
        }
      })
    },
    handleDel(row) {
      privilegeDelete(row.id).then((res) => {
        if (res.code == 200) {
          this.$message.success('删除成功!!')
          this.getTable()
        }
      })
    }
  }
}
</script>

<style scoped lang="scss">

.privilege {
  width: 100px;
  padding: 5px;
  border: 1px solid #eee;
}

</style>
